package com.users.entities;

import com.common.entities.AbstractDomainEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

/**
 * 用户类
 */

/**
 * 用户类
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "user")
public class User
        extends AbstractDomainEntity
        implements UserDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_GENDERATOR")
    @Schema(description = "主键")
    private Long id;

    @Column(nullable = false, length = 63, unique = true)
    @Schema(description = "用户名")
    private String username;

    @Schema(description = "密码", hidden = true)
    private String password;
    @Schema(description = "联系方式")
    // @Pattern(regexp = "^1(3|4|5|7|8)\\d{9}$", message = "手机号码格式错误！")
    private String tel;

    @Schema(description = "邮箱")
    private String email;

    @Schema(description = "账户是否可用")
    private boolean enabled = true;

    @Schema(description = "凭据是否未过期")
    private boolean credentialsNonExpired = true;

    @Schema(description = "账号是否未锁定")
    private boolean accountNonLocked = true;

    @Schema(description = "账户是否未过期")
    private boolean accountNonExpired = true;

    @Schema(description = "密码过期时间，密码有效时间")
    private Date credentialsExpiredDate;

    @Schema(description = "账号过期时间（账号有效时间）")
    private Date accountExpiredDate;

    @Schema(description = "手机号")
    private String mobilePhone;



    //
    @JsonIgnore
    @Transient
    private String secret;
    //
    //@JsonIgnore
    @Transient
    private String accessToken;

    /**
     * Returns the authorities granted to the user. Cannot return <code>null</code>.
     *
     * @return the authorities, sorted by natural key (never <code>null</code>)
     */
    @Transient
    @Override
    @JsonIgnore
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return new ArrayList<>();
    }
}